import { filterObj } from '@/utils/util';
import { deleteAction, getAction,downFile,getFileAccessHttpUrl,httpAction } from '@/api/manage'
import Vue from 'vue'
import { ACCESS_TOKEN } from "@/store/mutation-types"
import debounce from 'lodash/debounce';
import { create } from 'qrcode';

// 定义键盘码常量以提高可读性和可维护性
const KEY_F1 = 112;
const KEY_F2 = 113;
const KEY_F3 = 114;
const KEY_F4 = 115;
const KEY_F6 = 117;
const KEY_F7 = 118;
const KEY_F8 = 119;
const KEY_F9 = 120;
const KEY_ESC = 27;
const KEY_DEL = 8;
const KEY_SPACE = 32;
const KEY_ENTER = 13;
const otherModalKeyMinxin = {
  data() {
    return {
      keyDownObj:{
        autoIndex:0,
        autoHaoCaiIndex:1,
        KEY_CODE:'',
      
      },
      keyArr:[KEY_F2,KEY_F3,KEY_F4,KEY_F6,KEY_F7,KEY_F8,KEY_F9,KEY_ESC,KEY_DEL,KEY_SPACE,KEY_ENTER],
      tableDom:'#listTable',
    }
  },
  activated() {
  
  },
  created() {
    
    
  },
  watch: {
    visible(nv,ov){
    console.log(nv,ov,'222222visible')
    if(nv){
      document.addEventListener('keydown', this.handleModalKeyPress)
    }else{
      document.removeEventListener('keydown',this.handleModalKeyPress);
    }
   }
  },
  beforeDestroy(){
    
  },
  methods: {
    returnCodeText(val){
      var a = ''
      if(val == '112'){
        a = 'F1'
    }
      if(val == '113'){
          a = 'F2'
      }
      if(val == '114'){
        a = 'F3'
      }
      if(val == '115'){
          a = 'F4'
      }
      if(val == '117'){
          a = 'F6'
      }
      if(val == '118'){
          a = 'F7'
      }
      if(val == '119'){
          a = 'F8'
      }
      if(val == '120'){
          a = 'F9'
      }
      if(val == '121'){
        a = 'F10'
      }
      if(val == '27'){
          a = 'ESC'
      }
      if(val == '8'){
          a = 'DEL'
      }
      if(val == '32'){
          a = 'SPACE'
      }
      if(val == '13'){
        a = '回车'
    }
      return  a
    },
    handleModalKeyPress(e){
        var that = this;
        if (e.key == 'F1' || e.key === 'F2'  || e.key === 'F3' || e.key === 'F4' || e.key === 'F6' || e.key === 'F7' || e.key === 'F8' || e.key === 'F9' || e.key === 'F10' || e.key === 'F11' || e.key === 'F12') {
          e.preventDefault();
          console.log('F7 被禁用');
        }
        console.log(e.keyCode,'otherModalKeyMinxin',that.returnCodeText(e.keyCode))
        that.keyArr.forEach(element => {
          if(element == e.keyCode){
            // this.$notification['success']({
            //   message: that.returnCodeText(e.keyCode)+'键被按下!',
            //   duration:1,
            //   placement:'bottomRight'
             
            // });
            $('.ant-modal-content button').filter(function() {
                return $(this).text().indexOf(that.returnCodeText(e.keyCode)) !== -1;
            }).each(function() {
                $(this).click();
            });
          }
        });
        // if (e.keyCode === KEY_F4) {
        //   $('button').filter(function() {
        //       return $(this).text().indexOf(that.returnCodeText(e.keyCode)) !== -1;
        //   }).each(function() {
        //       $(this).click();
        //   });
        // }
        
    },
    
  }
  
 
}

export { otherModalKeyMinxin }